#!/usr/bin/env python
#coding:utf-8
#filename:pycdc-v0.5.py

import sys
import cmd
from cdctools import *

class PyCDC(cmd.Cmd):
    def __init__(self):
        cmd.Cmd.__init__(self)
        self.CDROM = '/home/wwq/音乐'
        #self.CDROM = '/home/wwq/py/gp'
        self.CDDIR = 'cdc/'
        self.prompt = '(PyCDC)>'
        self.intro = '''PyCDC 0.5 使用说明：
        dir 目录名     #指定保存和搜索目录，默认是"cdc"
        walk 文件名    #指定光盘信息文件名，使用"*.cdc"
        find 关键词    #使用在保存和搜索目录中遍历所有.cdc文件,输出含有关键词的行
        ?            #查询
        quit         #退出系统，也可用Ctrl+z
        '''

    def help_quit(self):
        print "退出程序 Quits the program"

    def do_quit(self, line):
        sys.exit()

    def help_walk(self):
        print "扫描光盘内容 walk cd and export into *.cdc"

    def do_walk(self, filename):
        if filename == "":
            filename = raw_input("输入cdc 文件名：")
        print "扫描光盘内容保存到:'%s'"%filename
        #cdWalker(self.CDROM, self.CDDIR+filename)
        #iniCDinfo(self.CDROM, self.CDDIR+filename)
        dictCDinfo(self.CDROM, self.CDDIR+filename)

    def help_dir(self):
        print "指定保存/搜索目录"

    def do_dir(self, pathname):
        if pathname == "":pathname = raw_input("输入指定保存/搜索目录：")
        self.CDDIR = pathname
        print "指定保存/搜索目录：'%s';默认是：'%s'" % (pathname, self.CDDIR)
        
    def help_find(self):
        print "搜索关键词"

    def do_find(self, keyword):
        if keyword == "":keyword = raw_input("输入搜索关键词：")
        print "搜索关键词：'%s'"%keyword
        cdcGrep(self.CDDIR, keyword)

    do_q = do_quit

if __name__ == '__main__':
    cdc = PyCDC()
    cdc.cmdloop()
    #cdrom = '/home/wwq/py/gp'
    #cdWalker(cdrom, 'cdc/cdctools.cdc')
